package cannot.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cannot.mapper.UserDetailMapper;
import cannot.pojo.UserDetail;
import cannot.pojo.UserDetailExample;
import cannot.service.UserDetailService;

@Service
public class UserDetailServiceImpl implements UserDetailService {
	@Autowired
	UserDetailMapper userDetailMapper;

	@Override
	public void addUserDetail(UserDetail userDetail) {
		userDetailMapper.insert(userDetail);
	}

	@Override
	public UserDetail getByForeginKey(Long id) {
		UserDetailExample example = new UserDetailExample();
		example.createCriteria().andForeginkeyEqualTo(id);
		List<UserDetail> userDetails = userDetailMapper.selectByExample(example);
		if(userDetails!=null&&userDetails.size()!=0){
			return userDetails.get(0);
		}else{
			return null;
		}
	}

	@Override
	public void updateUserDetail(UserDetail userDetail) {
		userDetailMapper.updateByPrimaryKeySelective(userDetail);
	}

}
